
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>MLSQL Python支持 · MLSQL Engine 文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/image.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="env.html" />
    
    
    <link rel="prev" href="../api/run-script.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    MLSQL Engine产品简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../howtouse/">
            
                <a href="../howtouse/">
            
                    
                    MLSQL Engine基本安装
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../howtouse/configuration.html">
            
                <a href="../howtouse/configuration.html">
            
                    
                    启动参数详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../howtouse/deploy.html">
            
                <a href="../howtouse/deploy.html">
            
                    
                    Local
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../howtouse/k8s_deploy.html">
            
                <a href="../howtouse/k8s_deploy.html">
            
                    
                    K8s部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../howtouse/yarn_deploy.html">
            
                <a href="../howtouse/yarn_deploy.html">
            
                    
                    Yarn部署
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../security/README.md">
            
                <span>
            
                    
                    MLSQL Engine安全加固
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../security/token_control.html">
            
                <a href="../security/token_control.html">
            
                    
                    接口访问Token设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../security/custom_control.html">
            
                <a href="../security/custom_control.html">
            
                    
                    自定义接口访问策略
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../auth/">
            
                <a href="../auth/">
            
                    
                    MLSQL Engine数据访问控制
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" >
            
                <span>
            
                    
                    解析时表权限
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" >
            
                <span>
            
                    
                    运行时表权限表以及列权限
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" >
            
                <span>
            
                    
                    客户端开发
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" >
            
                <span>
            
                    
                    服务端开发
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../api/README.md">
            
                <span>
            
                    
                    MLSQL Engine Rest接口详解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../api/run-script.html">
            
                <a href="../api/run-script.html">
            
                    
                    /run/script
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="./">
            
                <a href="./">
            
                    
                    MLSQL Python支持
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="etl.html">
            
                <a href="etl.html">
            
                    
                    数据处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="train.html">
            
                <a href="train.html">
            
                    
                    模型训练
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="pyjava.html">
            
                <a href="pyjava.html">
            
                    
                    PyJava API简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="read_excel.html">
            
                <a href="read_excel.html">
            
                    
                    结合Python读取Excel
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="write_excel.html">
            
                <a href="write_excel.html">
            
                    
                    结合Python保存Excel
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="resource.html">
            
                <a href="resource.html">
            
                    
                    K8s下的Python资源限制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="datamode.html">
            
                <a href="datamode.html">
            
                    
                    dataMode 详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="py_paralell.html">
            
                <a href="py_paralell.html">
            
                    
                    Python并行度你所需要知道的
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../plugin/">
            
                <a href="../plugin/">
            
                    
                    插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../plugin/online_install.html">
            
                <a href="../plugin/online_install.html">
            
                    
                    网络安装插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../plugin/offline_install.html">
            
                <a href="../plugin/offline_install.html">
            
                    
                    离线安装插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >MLSQL Python支持</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="mlsql-python&#x652F;&#x6301;">MLSQL Python&#x652F;&#x6301;</h1>
<p>MLSQL &#x4EE5;&#x4E00;&#x79CD;&#x975E;&#x5E38;&#x521B;&#x65B0;&#x7684;&#x65B9;&#x5F0F;&#x652F;&#x6301;Python,&#x4ECE;&#x800C;&#x5B8C;&#x6210;ETL&#x4EE5;&#x53CA;&#x7B97;&#x6CD5;&#x8BAD;&#x7EC3;&#xFF0C;&#x9884;&#x6D4B;&#x3002;</p>
<ol>
<li>Python&#x4EE3;&#x7801;&#x65E2;&#x53EF;&#x4EE5;&#x4EE5;&#x5B57;&#x7B26;&#x4E32;&#x5F62;&#x5F0F;&#x5185;&#x5D4C;&#x5230;MLSQL&#x4E2D;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5355;&#x72EC;&#x6210;&#x811A;&#x672C;Include&#x8FDB;MLSQL&#x4E2D;&#x3002;</li>
<li>Python&#x5BF9;&#x6570;&#x636E;&#x5904;&#x7406;&#x7684;&#x65B9;&#x5F0F;&#x4E5F;&#x662F;&#x8868;&#x8FDB;&#x8868;&#x51FA;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Python&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;ETL&#x4E5F;&#x53EF;&#x4EE5;&#x505A;&#x7B97;&#x6CD5;&#x8BAD;&#x7EC3;&#xFF0C;&#x9884;&#x6D4B;&#x7B49;&#x7B49;&#xFF0C;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x7EA6;&#x675F;&#x3002;</li>
<li>&#x65E0;&#x7F1D;&#x6574;&#x5408;Ray,&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Ray API &#x8FDB;&#x884C;&#x5206;&#x5E03;&#x5F0F;&#x8BA1;&#x7B97;&#xFF0C;&#x4EA6;&#x6216;&#x662F;&#x673A;&#x5668;&#x5B66;&#x4E60;&#x8BAD;&#x7EC3;&#x9884;&#x6D4B;&#x3002;</li>
</ol>
<h2 id="&#x5178;&#x578B;&#x793A;&#x4F8B;">&#x5178;&#x578B;&#x793A;&#x4F8B;</h2>
<p>&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x5206;&#x522B;&#x5BF9;&#x5E94;&#x63A7;&#x5236;&#x53F0;&#x7684;&#x4E24;&#x4E2A;&#x811A;&#x672C;:</p>
<p></p><div class="image-wrapper python-README"><a href="http://docs.mlsql.tech/upload_images/17372336-9ffb-4565-bef0-daa1ec9c1699.png" data-lightbox="9612749b-1b2e-42ee-be3d-272d578794a6" data-title="" target="_blank"><img src="http://docs.mlsql.tech/upload_images/17372336-9ffb-4565-bef0-daa1ec9c1699.png" alt=""></a></div><p></p>
<p>&#x5927;&#x5BB6;&#x53EF;&#x4EE5;&#x770B;&#x770B;MLSQL&#x662F;&#x5BF9;&#x4ED6;&#x4EEC;&#x5982;&#x4F55;&#x8FDB;&#x884C;&#x6709;&#x673A;&#x6574;&#x5408;&#x7684;&#x3002;</p>
<h3 id="foreachmlsql">foreach.mlsql</h3>
<pre><code class="lang-sql"><span class="hljs-comment">-- &#x52A0;&#x8F7D;python&#x811A;&#x672C;</span>
!pyInclude ray_data.foreach.py named wow1;

<span class="hljs-comment">-- &#x52A0;&#x8F7D;&#x5E76;&#x4E14;&#x5904;&#x7406;&#x6570;&#x636E;</span>
<span class="hljs-keyword">load</span> delta.<span class="hljs-string">`public.consumer_complains`</span> <span class="hljs-keyword">as</span> cc;
<span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> cc 
<span class="hljs-keyword">union</span> all <span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> cc 
<span class="hljs-keyword">union</span> all <span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> cc 
<span class="hljs-keyword">union</span> all <span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> cc 
<span class="hljs-keyword">as</span> newcc;

<span class="hljs-comment">-- ray &#x914D;&#x7F6E;</span>
!python env &quot;PYTHON_ENV=source activate dev&quot;;
!python conf &quot;schema=st(field(ProductName,string),field(SubProduct,string))&quot;;
!python conf &quot;runIn=driver&quot;;
!python conf &quot;dataMode=data&quot;;

<span class="hljs-comment">-- ray&#x5904;&#x7406;&#x6570;&#x636E;&#x4EE3;&#x7801;</span>
!ray on newcc py.wow1 named mlsql_temp_table2;

<span class="hljs-comment">--&#x7ED3;&#x679C;</span>
save overwrite mlsql_temp_table2 as parquet.`/tmp/mlsql_temp_table2`;
<span class="hljs-keyword">load</span>  parquet.<span class="hljs-string">`/tmp/mlsql_temp_table2`</span> <span class="hljs-keyword">as</span> mlsql_temp_table3;
</code></pre>
<h3 id="foreachpy">foreach.py</h3>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> ray
<span class="hljs-keyword">from</span> pyjava.api.mlsql <span class="hljs-keyword">import</span> RayContext
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np;

ray_context = RayContext.connect(globals(),<span class="hljs-string">&quot;192.168.209.29:49417&quot;</span>)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">echo</span><span class="hljs-params">(row)</span>:</span>
    row1 = {}
    row1[<span class="hljs-string">&quot;ProductName&quot;</span>]=<span class="hljs-string">&quot;jackm&quot;</span>
    row1[<span class="hljs-string">&quot;SubProduct&quot;</span>] = row[<span class="hljs-string">&quot;SubProduct&quot;</span>]
    <span class="hljs-keyword">return</span> row1


ray_context.foreach(echo)
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../api/run-script.html" class="navigation navigation-prev " aria-label="Previous page: /run/script">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="env.html" class="navigation navigation-next " aria-label="Next page: 环境依赖">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"MLSQL Python支持","level":"1.6","depth":1,"next":{"title":"环境依赖","level":"1.6.1","depth":2,"path":"python/env.md","ref":"python/env.md","articles":[]},"previous":{"title":"/run/script","level":"1.5.1","depth":2,"path":"api/run-script.md","ref":"api/run-script.md","articles":[]},"dir":"ltr"},"config":{"plugins":["image-class","lightbox"],"styles":{"website":"styles/image.css"},"pluginsConfig":{"image-class":{},"lightbox":{"jquery":true,"sameUuid":false},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"MLSQL Engine 文档","gitbook":"*","description":"MLSQL Engine 官方文档"},"file":{"path":"python/README.md","mtime":"2020-08-31T10:51:02.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-03T03:59:44.434Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

